﻿<local:BaseLab x:Class="Rxx.Labs.Reactive.UI.ObservableSyndicationLab"
							 xmlns:local="clr-namespace:Rxx.Labs"
							 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
							 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
							 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
							 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
							 xmlns:cm="clr-namespace:System.ComponentModel;assembly=System.Windows"
							 mc:Ignorable="d" 
							 d:DesignHeight="300" d:DesignWidth="300"
							 DataContext="{Binding RelativeSource={RelativeSource Self}}">

	<local:BaseLab.Resources>
		<CollectionViewSource x:Key="Feed">
			<CollectionViewSource.SortDescriptions>
				<cm:SortDescription PropertyName="Value.LastUpdatedTime" Direction="Descending" />
			</CollectionViewSource.SortDescriptions>
		</CollectionViewSource>
	</local:BaseLab.Resources>

	<Grid>
		<Grid.RowDefinitions>
			<RowDefinition Height="Auto" />
			<RowDefinition Height="200" />
		</Grid.RowDefinitions>

		<StackPanel Grid.Row="0">
			<StackPanel.Resources>
				<Style TargetType="TextBox">
					<Setter Property="VerticalAlignment" Value="Center" />
				</Style>
			</StackPanel.Resources>

			<Grid>
				<Grid.ColumnDefinitions>
					<ColumnDefinition Width="Auto" />
					<ColumnDefinition />
				</Grid.ColumnDefinitions>

				<TextBlock Grid.Column="0"  VerticalAlignment="Center" Text="Feed: " />
				<TextBox Grid.Column="1" Name="FeedTextBox" Text="{Binding FeedUrl, Mode=TwoWay, ValidatesOnExceptions=True}" />
			</Grid>

			<StackPanel Orientation="Horizontal">
				<RadioButton GroupName="Format" Content="RSS 2.0" IsChecked="{Binding IsFormatRss, Mode=TwoWay}" />
				<RadioButton GroupName="Format" Content="Atom 1.0" IsChecked="True" />
			</StackPanel>

			<Grid>
				<Grid.ColumnDefinitions>
					<ColumnDefinition Width="Auto" />
					<ColumnDefinition />
				</Grid.ColumnDefinitions>

				<TextBlock Grid.Column="0" VerticalAlignment="Center" Text="Auto refresh (hh:mm:ss:): " />
				<TextBox Grid.Column="1" Name="AutoDownloadIntervalTextBox" Text="{Binding AutoRefreshInterval, Mode=TwoWay, ValidatesOnExceptions=True}" />
			</Grid>

			<Grid>
				<Button Name="ApplySettingsButton" Content="Apply Settings"
								VerticalAlignment="Center" HorizontalAlignment="Center"
								Click="ApplySettingsButton_Click" />
			</Grid>

			<StackPanel Orientation="Horizontal">
				<TextBlock Text="{Binding Count, Source={StaticResource Feed}}" />
				<TextBlock Text=" Item(s)" />
			</StackPanel>
		</StackPanel>

		<ScrollViewer Grid.Row="1">
			<ItemsControl ItemsSource="{Binding Source={StaticResource Feed}}">

				<ItemsControl.ItemTemplate>
					<DataTemplate>

						<StackPanel Margin="0,7">
							<TextBlock Text="{Binding Value.LastUpdatedTime}" FontWeight="Light" />
							<TextBlock Text="{Binding Value.Title.Text}" FontWeight="Bold" />
						</StackPanel>

					</DataTemplate>
				</ItemsControl.ItemTemplate>

			</ItemsControl>
		</ScrollViewer>

	</Grid>

</local:BaseLab>